<?php
class GuestbookAction extends CommonAction {
    public function index(){
		$this->dao=D('Guestbook');
		$this->curcate = M('Category')->where(array('name' => 'Guestbook', 'site_id' => __SITEID__))->find();
		$this->initView();
		
		$this->dao->_list($this->view, array('site_id' => __SITEID__),'id desc',5);
		//$this->list = $this->dao->where(array('site_id' => __SITEID__)) -> select();
		if($this->_get('openid')){
			$this->member = M('member')->where(array('openid' => $this->_get('openid')))->find();
		}
		$this->display();
    }
	//写入留言 
	public function insert(){
		/*if(!$this->check_verify($this->_post('verify'),'mycms')){
				session('mycms','');
			    $this->error('验证码错误！');
		}*/
			$this->dao=D('Guestbook');
			$_POST['site_id']=__SITEID__;
			if($this->dao->create()){
				if($this->dao->add()){
					
					import('@.ORG.Mail');
					//dump($_POST);exit(); 
					$_POST['email']=$_POST['e-mail'];
					$this->assign($_POST);
					SendMail(getSysVal('email'),$_POST['yourname'].'的留言',$this->fetch('Public:mailTpl'),'');
					if(isset($_POST['option'])){
						$success = $_POST['option'];
					}else{
						$success = '操作成功!';
					}
					$this->success($success);
				}else{
					$this->error($this->dao->getError());
				}
			}else{
				$this->error($this->dao->getError());
			}
	    
	}
	//验证码
	public function verify(){
		import('@.ORG.Verify');
		$Verify = new Verify();
		$Verify->entry('mycms');
	}
	//检查验证码
	function check_verify($code, $id = ''){
		import('@.ORG.Verify');
		$verify = new Verify();
		return $verify->check($code, $id);
	}
}